<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.security.PublicKey" %>
<%@ page import="java.util.List" %>
<%@ page import="com.atguigu.pojo.Student" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: hasee
  Date: 2021/6/2
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <%--
    1. 遍历 1 到 10，输出
        begin属性设置开始的索引
        end属性设置结束的索引
        var属性表示循环的遍历(也是当前正在遍历到的数据)

        for(int i=10;i<10;i++){
        }
    --%>
    <table border="1" cellspacing="0">
        <c:forEach begin="1" end="10" var="i">
        <tr>
            <td>第${i}行</td>
        </tr>
        </c:forEach>
    </table>

    <hr>
    <%--2. 遍历 Object 数组
        for(Object:arr)
           items表示遍历的数据源（遍历的集合）
           var表示当前遍历到的数据
     --%>
    <%
        request.setAttribute("arr",new String[]{"18610541354","18688886666","18699998888"});
    %>
    <hr>
    ${requestScope.arr[0]}
    ${requestScope.arr[1]}
    ${requestScope.arr[2]}
    <hr>
    <c:forEach items="${requestScope.arr}" var="item">
        ${item} <br/>
    </c:forEach>
    <hr>
    <%
        Map<String,Object> map=new HashMap<>();
        map.put("key1","value1");
        map.put("key2","value2");
        map.put("key3","value3");
//        for(Map.Entry<String,Object> entry=map.entrySet()){
//        }
        request.setAttribute("map",map);
    %>
    <c:forEach items="${requestScope.map}" var="entry">
        ${entry}
        ${entry.key}=${entry.value}<br/>
    </c:forEach>
    <%--4. 遍历 List 集合---list 中存放 Student 类，有属性：编号，用户名，密码，年龄， 电话信息--%>
        <%
            List<Student> studentList=new ArrayList<>();
            for (int i = 1; i <10 ; i++) {
                studentList.add(new Student(i,"username"+i,"pass"+i,18+i,"phone"+i));
            }
            request.setAttribute("stus",studentList);
        %>

    <form action=""enctype=""></form>

    <table border="1px" cellspacing="0" >
        <tr>
            <th>编号</th>
            <th>用户名</th>
            <th>密码</th>
            <th>年龄</th>
            <th>电话</th>
            <th>操作</th>
        </tr>
        <%--
            items 表示遍历的集合
            var 表示遍历到的数据
            begin 表示遍历开始索引值
            begin 表示遍历结束索引值
            step 属性表示遍历的步长值

        --%>
        <c:forEach begin="2" end="7" step="1" varStatus="status" items="${requestScope.stus}" var="stu">
        <tr>
            <td>${stu.id}</td>
            <td>${stu.username}</td>
            <td>${stu.password}</td>
            <td>${stu.age}</td>
            <td>${stu.phone}</td>
            <td>${status.first}</td>
        </tr>
        </c:forEach>
    </table>

</body>
</html>
